﻿#########################################################################################################
####	Author: Rahul G. Babar																		 ####
####    Purpose: Use this PowerShell script to activate the web site feature if it is not already    ####
####             activated. Edit the script for specific requriements. 								 ####
#########################################################################################################

$webUrl = read-host "Enter web site Url (ex. http://sp2010server:1234/) "
$featureName = read-host "Enter web site level feature folder name which you want to activate"
if(($webUrl -ne $null) -and ($webUrl -ne "") -and ($featureName -ne $null) -and ($featureName -ne ""))
{
	$webSite = Get-SPWeb -Identity $webUrl -ErrorAction SilentlyContinue
	if($webSite -ne $null)
	{
		$webFeature = Get-SPFeature -Web $webSite | Where-object {$_.DisplayName -eq $featureName}	-ErrorAction SilentlyContinue
		if($webFeature -ne $null)
		{
			write-host "$featureName feature is already activated at website $webUrl." -foregroundcolor Green
			write-host
		}
		else
		{
			write-host "$featureName Feature is not activated, activating the same." -foregroundcolor Yellow
			write-host
			Enable-SPFeature -Identity $featureName -URL $webUrl -Force
			write-host "$featureName feature activated at website $webUrl." -foregroundcolor Green
			write-host
		}
	}
	else
	{
		write-host "Could not find website at $webUrl" -foregroundcolor Red
	}
}
else
{
	write-error "Invalid Website Url or feature name Entered."
}